package com.zch.mobile;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.base.mobile.MobException;
import com.base.mobile.MobileInfo;
import com.base.mobile.server.annotation.Mobile;
import com.base.mobile.server.annotation.MobileMethod;
import com.base.util.DateUtil;
import com.bf.common.proto.MCommon.MRet;
import com.bf.common.proto.MZxMessage.ZxMessagedetail;
import com.bf.common.proto.MZxMessage.ZxMessagedetailList;
import com.item.service.MessageService;
import com.zch.dao.model.Ability;
import com.zch.dao.model.ApplyProject;
import com.zch.dao.model.Bank;
import com.zch.dao.model.Collegemessage;
import com.zch.dao.model.Policy;
import com.zch.dao.model.ServiceOrganization;
import com.zch.dao.model.MyActivity;
import com.zch.dao.model.Technologymessage;
import com.zch.dao.model.Xqmessage;
import com.zch.dao.model.Zaiti;
import com.zch.dao.model.ZxMessage;
import com.zch.daoEx.model.ZxMessageEx;
import com.zch.service.AbilityService;
import com.zch.service.ApplyProjectService;
import com.zch.service.BankService;
import com.zch.service.CollegemessageService;
import com.zch.service.MyActivityService;
import com.zch.service.PolicyService;
import com.zch.service.ServiceOrganizationService;
import com.zch.service.TechnologymessageService;
import com.zch.service.XqmessageService;
import com.zch.service.ZaitiService;
import com.zch.service.ZxMessageService;

@Mobile
@Component
public class MSendMsg {

    @Autowired
    private ZxMessageService zxMessageService;
    @Autowired
    private ZaitiService zaitiService;
    @Autowired
    private XqmessageService xqmessageService;
    @Autowired
    private MessageService messageService;
    @Autowired
    private TechnologymessageService technologymessageService;
    @Autowired
    private CollegemessageService collegemessageService;
    @Autowired
    private PolicyService policyService;
    @Autowired
    private MyActivityService myActivityService;
    @Autowired
    private AbilityService abilityService;
    @Autowired
    private ServiceOrganizationService serviceOrganizationService;
    @Autowired
    private ApplyProjectService applyProjectService;
    @Autowired
    private BankService bankService;
    /**
     * 发布资讯
     * @param mobileInfo
     * @param type  发布类型 0：发布   1：转载
     * @param title     资讯标题
     * @param content       资讯内容
     * @param images    图片
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendZx", isLogin = true)
    public MRet.Builder SendZx(MobileInfo mobileInfo, String type, 
                               String title, 
                               String content, 
                               String images,
                               String city) throws Exception{
        if (StringUtils.isBlank(type)) throw new MobException("type");
        if (StringUtils.isBlank(title)) throw new MobException("title");
        if (StringUtils.isBlank(content)) throw new MobException("content");
        if (StringUtils.isBlank(city)) throw new MobException("city");
        MRet.Builder ret= MRet.newBuilder();
        if(content.length()>=1500){
            ret.setCode(-1);
            ret.setMsg("内容请控制在1500字以内...");
        }
//        content.replaceAll("\\s", "&nbsp;");
        ZxMessage zxMessage = new ZxMessage();
        zxMessage.setType(Integer.parseInt(type));
        zxMessage.setZxTitle(title);
        zxMessage.setContent(content);
        zxMessage.setImage(images);
        zxMessage.setUserId(mobileInfo.getUserid());
        zxMessage.setCity(city);
        zxMessage.setIsAgree(0);
        zxMessage.setIsIndexImage(0);
        zxMessage.setBannerImages("");
        /*content.replace("\n", "<br/>");*/        
        int result = zxMessageService.insert(zxMessage);
        if (result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 资讯发布地区
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendZxCity", isLogin = false)
    public JSONArray SendZxCity()throws Exception{
    	JSONArray array = new JSONArray();
    	JSONObject object = new JSONObject();
    	JSONObject object2 = new JSONObject();
    	JSONObject object3 = new JSONObject();
    	object.put("id", "1");
    	object.put("cityName", "钟楼区");
    	array.add(object);
    	object2.put("id", "2");
    	object2.put("cityName", "兄弟城区");
    	array.add(object2);
    	object3.put("id", "3");
    	object3.put("cityName", "常州市");
    	array.add(object3);
        return array;
    }
    
    /**
     * 发布载体
     * @param mobileInfo
     * @param name
     * @param enterNumber
     * @param zaitiType
     * @param address
     * @param area
     * @param rental
     * @param content
     * @param images
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendZaiti", isLogin = true)
    public MRet.Builder SendZaiti(MobileInfo mobileInfo, String name, String zaitiType, String address, String area, String rental, String content, String images) throws Exception{
        if (StringUtils.isBlank(name)) throw new MobException("name");
        if (StringUtils.isBlank(zaitiType)) throw new MobException("zaitiType");
        if (StringUtils.isBlank(address)) throw new MobException("address");
        if (StringUtils.isBlank(area)) throw new MobException("area");
        if (StringUtils.isBlank(rental)) throw new MobException("rental");
        if (StringUtils.isBlank(content)) throw new MobException("content");
        MRet.Builder ret = MRet.newBuilder();
        if(content.length()>=1500){
            ret.setCode(-1);
            ret.setMsg("载体概况请控制在1500字以内...");
            return ret; 
        }
        /*if(!area.matches("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$")){*/
        if(!area.matches("^\\+?[1-9][0-9]*$")){   
            ret.setCode(-1);
            ret.setMsg("载体面积只能为正整数...");
            return ret;   
        }
        /*if(!rental.matches("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$")){
            ret.setCode(-1);
            ret.setMsg("请输入租金正确金额(小数点2位)...");
            return ret;   
        }*/
        
        Zaiti zaiti = new Zaiti();
        zaiti.setZaitiName(name);
        zaiti.setEnterNumber(1);
        zaiti.setZaitiType(zaitiType);
        zaiti.setAddress(address);
        zaiti.setArea(area);

        zaiti.setRental(rental);
        zaiti.setContent(content);
        zaiti.setImage(images);
        zaiti.setUserId(mobileInfo.getUserid());
        zaiti.setIsAgree(0);
        
        int result = zaitiService.insert(zaiti);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        ret.setCode(1);
        
       
        return ret;
        
    }
    
    /**
     * 发布需求
     */
    @MobileMethod(methodno = "MSendXq", isLogin = true)
    public MRet.Builder MSendXq(MobileInfo mobileInfo,
                                String name, 
                                String trade, 
                                String serviceType,
                                String havezl,
                                String money,
                                String college,
                                String professor,
                                String content,
                                String companyname,
                                String product,
                                String address,
                                String manager,
                                String phone)throws Exception{
        if (StringUtils.isBlank(name)) throw new MobException("name");
        if (StringUtils.isBlank(trade)) throw new MobException("trade");
        if (StringUtils.isBlank(serviceType)) throw new MobException("serviceType");
        if (StringUtils.isBlank(havezl)) throw new MobException("havezl");
        if (StringUtils.isBlank(money)) throw new MobException("money");
        if (StringUtils.isBlank(college)) throw new MobException("college");
        if (StringUtils.isBlank(professor)) throw new MobException("professor");
        if (StringUtils.isBlank(content)) throw new MobException("content");
        if (StringUtils.isBlank(companyname)) throw new MobException("companyname");
        if (StringUtils.isBlank(product)) throw new MobException("product");
        if (StringUtils.isBlank(address)) throw new MobException("address");
        if (StringUtils.isBlank(manager)) throw new MobException("manager");
        if (StringUtils.isBlank(phone)) throw new MobException("phone");
        MRet.Builder ret = MRet.newBuilder();
        
        Pattern pattern = Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$");
        Matcher isNum = pattern.matcher(money);
        if(!isNum.matches()){
            ret.setCode(-1);
            ret.setMsg("请输入正确金额(小数点2位)...");
            return ret;
        }
        if(content.length()>=1500){
            ret.setCode(-1);
            ret.setMsg("内容请控制在1500个字以内...");
            return ret;
        }
        if(companyname.length()>=25){
            ret.setCode(-1);
            ret.setMsg("企业名称请控制在25个字以内...");
            return ret;
        }
        if(product.length()>=500){
            ret.setCode(-1);
            ret.setMsg("主要产品请控制在500个字以内...");
            return ret;
        }
        if(address.length()>=50){
            ret.setCode(-1);
            ret.setMsg("企业地址请控制在50个字以内...");
            return ret;
        }
        Xqmessage xqmessage = new Xqmessage();
        xqmessage.setUserId(mobileInfo.getUserid());
        xqmessage.setName(name);
        xqmessage.setDomainId(Integer.parseInt(trade));
        xqmessage.setServiceType(Integer.parseInt(serviceType));
        xqmessage.setHaveZl(Integer.parseInt(havezl));
        BigDecimal  str= new BigDecimal(money);
        xqmessage.setMoney(str);
        xqmessage.setCollege(college);
        xqmessage.setProfessor(professor);
        xqmessage.setContent(content);
        xqmessage.setCompanyname(companyname);
        xqmessage.setProduct(product);
        xqmessage.setAddress(address);
        xqmessage.setManager(manager);
        xqmessage.setPhone(phone);
        xqmessage.setIsAgree(0);
        int result = xqmessageService.insert(xqmessage);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 发布技术
     * @param mobileInfo
     * @param name 技术名称
     * @param trade_id 行业领域编号
     * @param teamWorkWayId 合作方式编号
     * @param haveZl 是否有专利 0:没有 1:有
     * @param area 所属高校
     * @param content 技术概况
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendTechnology", isLogin = true)
    public MRet.Builder SendTechnology(MobileInfo mobileInfo,
                                       String name,
                                       String trade_id,
                                       String teamWorkWayId,
                                       String haveZl,
                                       String area,
                                       String phone,
                                       String content)throws Exception{
        if (StringUtils.isBlank(name)) throw new MobException("name");
        if (StringUtils.isBlank(trade_id)) throw new MobException("trade_id");
        if (StringUtils.isBlank(teamWorkWayId)) throw new MobException("teamWorkWayId");
        if (StringUtils.isBlank(haveZl)) throw new MobException("haveZl");
        if (StringUtils.isBlank(area)) throw new MobException("area");
        if (StringUtils.isBlank(content)) throw new MobException("content");
        if (StringUtils.isBlank(phone)) throw new MobException("phone");
        MRet.Builder ret = MRet.newBuilder();
        if(area.length()>=50){
            ret.setCode(-1);
            ret.setMsg("所属高校/科研院所请控制在50个字以内...");
            return ret;
        }
        if(content.length()>=1500){
            ret.setCode(-1);
            ret.setMsg("概况请控制在1500个字以内...");
            return ret;
        }
        
        Technologymessage message = new Technologymessage();
        message.setUserId(mobileInfo.getUserid());
        message.setTechnologyName(name);
        message.setDomainId(Integer.parseInt(trade_id));
        message.setTeamworkWayId(teamWorkWayId);
        message.setHavezl(Integer.parseInt(haveZl));
        message.setArea(area);
        message.setContent(content);
        message.setIsAgree(0);
        message.setPhone(phone);
        
        int result = technologymessageService.insert(message);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 高校发布
     * @param mobileInfo
     * @param name  院校名称
     * @param address  院校地址
     * @param collegeMaster  分管校长
     * @param manager 负责人
     * @param phone 电话
     * @param yssubject 优势学科
     * @param tecresult 技术成果
     * @param content 概述
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendCollege", isLogin = true)
    public MRet.Builder SendCollege(MobileInfo mobileInfo,
                                    String name,
                                    String address,
                                    String collegeMaster,
                                    String manager,
                                    String phone,
                                    String yssubject,
                                    String tecresult,
                                    String content)throws Exception{
        if (StringUtils.isBlank(name)) throw new MobException("name");
        if (StringUtils.isBlank(address)) throw new MobException("address");
        if (StringUtils.isBlank(collegeMaster)) throw new MobException("collegeMaster");
        if (StringUtils.isBlank(manager)) throw new MobException("manager");
        if (StringUtils.isBlank(phone)) throw new MobException("phone");
        if (StringUtils.isBlank(yssubject)) throw new MobException("yssubject");
        if (StringUtils.isBlank(tecresult)) throw new MobException("tecresult");
        if (StringUtils.isBlank(content)) throw new MobException("content");
        MRet.Builder ret = MRet.newBuilder();
        if(name.length()>=50){
            ret.setCode(-1);
            ret.setMsg("高校名称请控制在50字以内...");
            return ret;
        }
        if(address.length()>=50){
            ret.setCode(-1);
            ret.setMsg("地址请控制在50字以内...");
            return ret;
        }
        if(collegeMaster.length()>=10){
            ret.setCode(-1);
            ret.setMsg("校长名字请控制在10字以内...");
            return ret;
        }
        if(yssubject.length()>=100){
            ret.setCode(-1);
            ret.setMsg("优势学科请控制在100字以内...");
            return ret;
        }
        if(content.length()>=1500){
            ret.setCode(-1);
            ret.setMsg("高校概述请控制在1500字以内...");
            return ret;
        }
        if(tecresult.length()>=100){
            ret.setCode(-1);
            ret.setMsg("技术成果请控制在100字以内...");
            return ret;
        }
        
        Collegemessage message = new Collegemessage();
        message.setName(name);
        message.setAddress(address);
        message.setCollegemaster(collegeMaster);
        message.setManager(manager);
        message.setPhone(phone);
        message.setYssubject(yssubject);
        message.setTecresult(tecresult);
        message.setContent(content);
        message.setIsAgree(0);
        message.setUserId(mobileInfo.getUserid());
        int result = collegemessageService.insert(message);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
       
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 发布政策
     * @param mobileInfo
     * @param type
     * @param title
     * @param deptno
     * @param content
     * @param image
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendPolicy", isLogin = true)
    public MRet.Builder SendPolicy(MobileInfo mobileInfo,
                                   String type,
                                   String title,
                                   String content,
                                   String image,
                                   String kind)throws Exception{
        if (StringUtils.isBlank(type)) throw new MobException("type");
        if (StringUtils.isBlank(title)) throw new MobException("title");
        /*if (StringUtils.isBlank(deptno)) throw new MobException("deptno");*/
        if (StringUtils.isBlank(content)) throw new MobException("content");
        if (StringUtils.isBlank(kind)) throw new MobException("kind");
        MRet.Builder ret = MRet.newBuilder();
        if(title.length()>=50){
            ret.setCode(-1);
            ret.setMsg("标题请控制在50个字以内...");
            return ret;
        }
        if(content.length()>=1500){
            ret.setCode(-1);
            ret.setMsg("内容请控制在1500个字以内...");
            return ret;
        }
        
        Policy message = new Policy();
        message.setType(Integer.parseInt(type));
        message.setTitle(title);
        message.setKind(kind);
        message.setContent(content);
        message.setImage(image);
        message.setUserId(mobileInfo.getUserid());
        message.setIsAgree(0);
        
        int result = policyService.insert(message);
        if(result==0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 政策发布种类
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendPolicyKind", isLogin = false)
    public JSONArray SendPolicyKind()throws Exception{
        JSONArray array = new JSONArray();
        JSONObject object = new JSONObject();
        object.put("id", "1");
        object.put("name", "发改");
        JSONObject object2 = new JSONObject();
        object2.put("id", "2");
        object2.put("name", "经信");
        JSONObject object3 = new JSONObject();
        object3.put("id", "3");
        object3.put("name", "科技");
        JSONObject object4 = new JSONObject();
        object4.put("id", "4");
        object4.put("name", "商务");
        JSONObject object5 = new JSONObject();
        object5.put("id", "5");
        object5.put("name", "人才");
        JSONObject object6 = new JSONObject();
        object6.put("id", "6");
        object6.put("name", "人社");
        JSONObject object7 = new JSONObject();
        object7.put("id", "7");
        object7.put("name", "团委");
        JSONObject object8 = new JSONObject();
        object8.put("id", "8");
        object8.put("name", "科协");
        JSONObject object9 = new JSONObject();
        object9.put("id", "9");
        object9.put("name", "工会");
        JSONObject object10 = new JSONObject();
        object10.put("id", "10");
        object10.put("name", "金融");
        JSONObject object11 = new JSONObject();
        object11.put("id", "11");
        object11.put("name", "其它");
        array.add(object);
        array.add(object2);
        array.add(object3);
        array.add(object4);
        array.add(object5);
        array.add(object6);
        array.add(object7);
        array.add(object8);
        array.add(object9);
        array.add(object10);
        array.add(object11);
        
        return array;
    }
    
    /**
     * 我参加的活动
     * @param mobileInfo
     * @param name
     * @param number
     * @param company
     * @param job
     * @param phone
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MMyActivityDetail", isLogin = true)
    public MRet.Builder MyActivityDetail(MobileInfo mobileInfo,
                                   String name,
                                   String number,
                                   String company,
                                   String job,
                                   String actid,
                                   String phone)throws Exception{
        if (StringUtils.isBlank(number)) throw new MobException("number");
        if (StringUtils.isBlank(company)) throw new MobException("company");
        if (StringUtils.isBlank(job)) throw new MobException("job");
        if (StringUtils.isBlank(phone)) throw new MobException("phone");
        if (StringUtils.isBlank(actid)) throw new MobException("actid");
        MRet.Builder ret = MRet.newBuilder();
        if(name.length()>10){
            ret.setCode(-1);
            ret.setMsg("姓名请控制在10个字以内...");
            return ret;
        }
        if(number.length()>1000){
            ret.setCode(-1);
            ret.setMsg("人数请控制在1000个人以内...");
            return ret;
        }
        if(company.length()>50){
            ret.setCode(-1);
            ret.setMsg("单位请控制在50个字以内...");
            return ret;
        }
        if(job.length()>10){
            ret.setCode(-1);
            ret.setMsg("职务请控制在10个字以内...");
            return ret;
        }
        if(phone.length()>11){
            ret.setCode(-1);
            ret.setMsg("联系方式请控制在15个字以内");
            return ret;
        }
        MyActivity myActivity = new MyActivity();
        myActivity.setCompany(company);
        myActivity.setName(name);
        myActivity.setJob(job);
        myActivity.setNumber(Integer.parseInt(number));
        myActivity.setPhone(phone);
        myActivity.setUserId(mobileInfo.getUserid());
        myActivity.setActId(actid);
        int result = myActivityService.insert(myActivity);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 人才项目
     * @param mobileInfo
     * @param title  标题
     * @param project_area  项目领域
     * @param message  项目介绍
     * @param person_message 人才简介
     * @param project_state 项目阶段
     * @param team_work_xq 合作需求
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "Mability", isLogin = true)
    public MRet.Builder Mability(MobileInfo mobileInfo,
                                         String title,
                                         String project_area,
                                         String message,
                                         String person_message,
                                         String project_state,
                                         String team_work_xq)throws Exception{
        
        if (StringUtils.isBlank(title)) throw new MobException("title");
        if (StringUtils.isBlank(project_area)) throw new MobException("project_area");
        if (StringUtils.isBlank(message)) throw new MobException("message");
        if (StringUtils.isBlank(person_message)) throw new MobException("person_message");
        if (StringUtils.isBlank(project_state)) throw new MobException("project_state");
        if (StringUtils.isBlank(team_work_xq)) throw new MobException("team_work_xq");
        MRet.Builder ret = MRet.newBuilder();
        if(title.length()>=250){
            ret.setCode(-1);
            ret.setMsg("标题请控制在250个字以内...");
            return ret;
        }
        if(project_area.length()>=500){
            ret.setCode(-1);
            ret.setMsg("项目领域请控制在500个字以内...");
            return ret;
        }
        if(message.length()>=500){
            ret.setCode(-1);
            ret.setMsg("项目介绍请控制在500个字以内...");
            return ret;
        }
        if(person_message.length()>=500){
            ret.setCode(-1);
            ret.setMsg("人才简介请控制在500个字以内...");
            return ret;
        }
        if(project_state.length()>=250){
            ret.setCode(-1);
            ret.setMsg("项目阶段请控制在250个字以内...");
            return ret;
        }
        if(team_work_xq.length()>=1000){
            ret.setCode(-1);
            ret.setMsg("合作需求请控制在1000个字以内...");
            return ret;
        }
        Ability ability = new Ability();
        ability.setTitle(title);
        ability.setProjectArea(project_area);
        ability.setMessage(message);
        ability.setPersonMessage(person_message);
        ability.setProjectState(project_state);
        ability.setTeamWorkXq(team_work_xq);
        ability.setUserId(mobileInfo.getUserid());
        ability.setIsAgree(0);
        int result = abilityService.insert(ability);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 发布服务机构
     * @param mobileInfo
     * @param type
     * @param title
     * @param company_zz
     * @param organization_msg
     * @param service_content
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MServiceOrganization", isLogin = true)
    public MRet.Builder MServiceOrganization(MobileInfo mobileInfo,
                                String type,
                                String title,
                                String company_zz,
                                String organization_msg,
                                String service_content)throws Exception{
        if (StringUtils.isBlank(type)) throw new MobException("type");
        if (StringUtils.isBlank(title)) throw new MobException("title");
        if (StringUtils.isBlank(organization_msg)) throw new MobException("organization_msg");
        if (StringUtils.isBlank(service_content)) throw new MobException("service_content");
        MRet.Builder ret = MRet.newBuilder();
        if(title.length()>=25){
            ret.setCode(-1);
            ret.setMsg("标题请控制在25个字以内...");
            return ret;
        }
        if(company_zz.length()>=250){
            ret.setCode(-1);
            ret.setMsg("企业资质请控制在250个字以内...");
            return ret;
        }
        if(organization_msg.length()>=500){
            ret.setCode(-1);
            ret.setMsg("机构简介请控制在500个字以内...");
            return ret;
        }
        if(service_content.length()>=1000){
            ret.setCode(-1);
            ret.setMsg("服务内容请控制在1000个字以内...");
            return ret;
        }
        ServiceOrganization serviceOrganization = new ServiceOrganization();
        if("1".equals(type)){
            serviceOrganization.setType("运营机构");
        }else if("2".equals(type)){
            serviceOrganization.setType("法律服务");
        }else if("3".equals(type)){
            serviceOrganization.setType("财会服务");
        }else if("4".equals(type)){
            serviceOrganization.setType("知识产权");
        }else if("5".equals(type)){
            serviceOrganization.setType("管理咨询");
        }else if("6".equals(type)){
            serviceOrganization.setType("其它");
        }            
        serviceOrganization.setTitle(title);
        serviceOrganization.setCompanyZz(company_zz);
        serviceOrganization.setOrganizationMsg(organization_msg);
        serviceOrganization.setServiceContent(service_content);
        serviceOrganization.setIsAgree(0);
        serviceOrganization.setUserId(mobileInfo.getUserid());
        int result = serviceOrganizationService.insert(serviceOrganization);
        if(result==0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 服务机构板块
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MServiceOrganizationKind", isLogin = false)
    public JSONArray MServiceOrganizationKind()throws Exception{
        JSONObject object1 = new JSONObject();
        object1.put("id", "1");
        object1.put("name", "运营机构");
        JSONObject object2 = new JSONObject();
        object2.put("id", "2");
        object2.put("name", "法律服务");
        JSONObject object3 = new JSONObject();
        object3.put("id", "3");
        object3.put("name", "财会服务");
        JSONObject object4 = new JSONObject();
        object4.put("id", "4");
        object4.put("name", "知识产权");
        JSONObject object5 = new JSONObject();
        object5.put("id", "5");
        object5.put("name", "管理咨询");
        JSONObject object6 = new JSONObject();
        object6.put("id", "6");
        object6.put("name", "其它");        
        JSONArray array = new JSONArray();
        array.add(object1);
        array.add(object2);
        array.add(object3);
        array.add(object4);
        array.add(object5);
        array.add(object6);
        return array;
    }
    
    /**
     * 发布项目申报 
     * @param mobileInfo
     * @param title
     * @param dept
     * @param message
     * @param applyEndTime
     * @param applyUrl
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendApplyProject", isLogin = true)
    public MRet.Builder MSendApplyProject(MobileInfo mobileInfo,
                                          String title,
                                          String dept,
                                          String message,
                                          String applyEndTime,
                                          String applyUrl)throws Exception{
        if (StringUtils.isBlank(title)) throw new MobException("title");
        if (StringUtils.isBlank(dept)) throw new MobException("dept");
        if (StringUtils.isBlank(message)) throw new MobException("message");
        if (StringUtils.isBlank(applyEndTime)) throw new MobException("applyEndTime");
        if (StringUtils.isBlank(applyUrl)) throw new MobException("applyUrl");
        MRet.Builder ret = MRet.newBuilder();
        if(title.length()>=100){
            ret.setCode(-1);
            ret.setMsg("标题请控制在100个字以内...");
            return ret;
        }
        if(message.length()>=1000){
            ret.setCode(-1);
            ret.setMsg("具体内容请控制在1000个字以内...");
            return ret;
        }       
        if(applyUrl.length()>=100){
            ret.setCode(-1);
            ret.setMsg("申报查询网址请控制在100长度以内...");
            return ret;
        }
        ApplyProject applyProject = new ApplyProject();
        applyProject.setTitle(title);
        applyProject.setDept(dept);
        applyProject.setMessage(message);
        applyProject.setApplyEndTime((DateUtil.strToDate(applyEndTime+":00")));
        applyProject.setApplyUrl(applyUrl);
        applyProject.setIsAgree(0);
        applyProject.setUserId(mobileInfo.getUserid());
        
        int result = applyProjectService.insert(applyProject);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 银行金融
     * @param mobileInfo
     * @param bankName
     * @param productName
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendBank", isLogin = true)
    public MRet.Builder SendBank(MobileInfo mobileInfo,
                                 String bankName,
                                 String productName)throws Exception{
        if (StringUtils.isBlank(bankName)) throw new MobException("bankName");
        if (StringUtils.isBlank(productName)) throw new MobException("productName");
        MRet.Builder ret = MRet.newBuilder();
        if(bankName.length()>=25){
            ret.setCode(-1);
            ret.setMsg("银行名称请控制在25个字以内...");
            return ret;
        }
        if(productName.length()>=1000){
            ret.setCode(-1);
            ret.setMsg("金融产品名称请控制在1000个字以内...");
            return ret;
        }
        Bank bank = new Bank();
        bank.setBankName(bankName);
        bank.setProductName(productName);
        bank.setIsAgree(0);
        bank.setUserId(mobileInfo.getUserid());
        int result = bankService.insert(bank);
        if(result==0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        ret.setCode(1);
        return ret;
    }
}
